MPBufferProxy : Buffer{

	classvar buffers;
	var <>numberOfUsers = 0;
	
	*init{
		buffers = Dictionary.new;
	}
	
	*read{|server, path, startFrame, numFrames, action, bufnum|
		var buffer;
		
		if(buffers == nil){
			this.init;
		};
		
		buffer = buffers.at(path);
		
		if(buffer == nil){
			buffer = super.read(Server.default, path, startFrame, numFrames);
			buffers.add(path -> buffer);
		};
		
		buffer.numberOfUsers = buffer.numberOfUsers + 1;
		
		^buffer;
	
	}
	
	free{
		numberOfUsers = numberOfUsers - 1;
		if(numberOfUsers == 0){
			buffers.removeAt(this.path);
			super.free;
		}	
	}

}


/*
			//var b, s, r, bufLength = 8, p;
			
			//s = s.default;
			
			b = Buffer.alloc(s, s.sampleRate * 1, 2, bufnum: 99999);
			
			SynthDef("OutTob",{|bufNum|
				
				RecordBuf.ar(In.ar(0,2), bufNum, recLevel:1, preLevel: 0 );
				
			}).send(s);
			
			SynthDef("bufp", {|bufNum, trig|
				
				var sig;
				
				sig = PlayBuf.ar(2, bufNum, trigger: trig, loop: 1);
			
				Out.ar(0, sig);
				
			}).send(s);
			
			SynthDef("tone", {|bufNum, trig|
				
				var sig;
				
				sig = SinOsc.ar(200) * Line.kr(1,0,8);
			
				Out.ar(0, sig);
				
			}).send(s);
			
			//t = Synth("tone");
			
			r = Synth("OutTob", [b.bufnum], addAction: \addToTail);
			
			p = Synth("bufp", [b.bufnum], addAction: \addToTail);
			
			SystemClock.sched(5, {r.free});
			
			
		*/